from docx import Document
import re

# 读取Word文档
doc_path = "/mnt/doc/1739180141_姜马陆的论文.docx"
doc = Document(doc_path)

# 正则表达式匹配角标引用，例如 [1]、[12]、[3,4] 等
citation_pattern = re.compile(r"\[\d+(?:,\d+)*\]")

# 定义句子分割规则，按照中文的句号、问号、感叹号进行分句
sentence_split_pattern = re.compile(r'(?<=[。！？])')

# 遍历文档，提取所有带引用的句子
citation_sentences = []

for para in doc.paragraphs:
    # print(para.text)
    text = para.text.strip()
    if not text:
        continue  # 跳过空段落
    
    # 先按照标点符号分割句子
    sentences = sentence_split_pattern.split(text)
    
    for sentence in sentences:
        if citation_pattern.search(sentence):  # 如果句子中包含引用
            citation_sentences.append(sentence.strip())

# 输出所有提取的引用句子
for i, sentence in enumerate(citation_sentences, 1):
    print(f"第{i}个引用句：{sentence}\n")